<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>业务模块-会员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="${s.base}/js/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="${s.base}/css/base/base.css?123456" media="all" /></head>

<body class="childrenBody">
<form class="layui-form">
    <blockquote class="layui-elem-quote quoteBox" id="tool">
        <div class="layui-inline">
            <label class="layui-input-inline">ID号</label>
            <label class="layui-input-inline">
                <input type="text" class="layui-input" name="cardNo" placeholder="请输入ID号" /></label>
            <label class="layui-input-inline">昵称</label>
            <label class="layui-input-inline">
                <input type="text" class="layui-input" name="nickName" placeholder="请输入昵称" /></label>
            <label class="layui-input-inline">头像</label>
            <label class="layui-input-inline">
                <input type="text" class="layui-input" name="headImage" placeholder="请输入头像" /></label>
            <label class="layui-input-inline">姓名</label>
            <label class="layui-input-inline">
            <input type="text" class="layui-input" name="name" placeholder="请输入姓名" /></label>
            <a class="layui-btn search_btn" lay-submit="" lay-filter="seacherBtn">搜索</a>
            <a class="layui-btn export_btn" lay-submit="" >导出</a>
        </div>
    </blockquote>
    <table id="entityList" lay-filter="entityList"></table>
</form>
<script type="text/javascript" src="${s.base}/js/layui/layui.js"></script>
<script type="text/javascript" src="${s.base}/js/base/base.js"></script>
<script type="text/javascript">layui.use(['jquery', 'form','pageUtil','dialogUtil',  'table', 'dateUtil'],
    function() {
        var $ = layui.jquery,
            dateUtil = layui.dateUtil,
            form = layui.form,
            dialogUtil = layui.dialogUtil,
            table = layui.table,
            pageUtil = layui.pageUtil;
        var url = "/webMember/page";
        var cols = [{
            type: 'checkbox',
            fixed: 'left'
        },
            {
                type: 'numbers',
                title: '序号'
            },
            {
                field: 'cardNo',
                title: 'ID号',
                align: 'center'
            },
            {
                field: 'nickName',
                title: '昵称',
                align: 'center'
            },
            {
                field: 'phone',
                title: '手机号',
                align: 'center'
            },
            {
                field: 'name',
                title: '姓名',
                align: 'center'
            },
            {
                field: 'money',
                title: '余额/元',
                align: 'center'
            },
            {field: 'recoveryPermission',width:100, title: '回收权限', align:'center', templet:function(d){
                if(d.recoveryPermission=="2"){
                    return '有';
                }else{
                    return '无';
                }
            }},
            {
                field: 'createTime',
                title: '创建时间',
                width: 190,
                align: 'center',
                templet: function(d) {
                    return dateUtil.formatDate(new Date(d.createTime), "yyyy-MM-dd HH:mm:ss");
                }
            },
            {
                title: '操作',
                width: 150,
                align: "center",
                fixed: 'right',
                templet: function(d) {
                    return '<a class="layui-btn cy-btnbg-edit layui-btn-sm" lay-event="shopEdit"> 添加费用 </a>';
                }

            }];
        var tableIns = pageUtil.initDate(cols, url, true);

        // 导出
        $(".export_btn").on("click",function(){
            var cardNo = $("input[name='cardNo']").val();
            var nickName = $("input[name='nickName']").val();
            var name = $("input[name='name']").val();
            window.location.href = "/webMember/export?cardNo="+cardNo+"&nickName="+nickName+"&name="+name;
        });

        // type类型开启
        form.on('switch(switchTypeOne)', function(obj){
            // 获取当前控件
            var id = $(this).attr("data-id");
            console.log(id);
            var status = "1";
            if (this.checked){
                status = "2";
            }
            $.post("/webMember/updatePermission",{
                "id":id,
                "consumePermission":status
            },function(result){
                if(1==result.code){
                    tableIns.reload();
                }else{
                    top.layer.msg(result.msg);
                }
            })
        });
        form.on('switch(switchTypeTwo)', function(obj){
            // 获取当前控件
            var id = $(this).attr("data-id");
            console.log(id);
            var status = "1";
            if (this.checked){
                status = "2";
            }
            $.post("/webMember/updatePermission",{
                "id":id,
                "recoveryPermission":status
            },function(result){
                if(1==result.code){
                    tableIns.reload();
                }else{
                    top.layer.msg(result.msg);
                }
            })
        });

        table.on('tool(entityList)',
            function(obj) {
                var layEvent = obj.event,
                    data = obj.data;
                if (layEvent === 'edit') {
                    pageUtil.editPopup("编辑", "/webMember/getEntity?id=" + data.id);
                } else if (layEvent === 'shopEdit') {
                    // 设置用户
                    var id = data.id;
                    var score = "";
                    if(data.score != null && data.score != ""){
                        score = data.score;
                    }
                    var index = layer.open({
                        type: 1,
                        title:'增加费用',
                        area: ['400px', 'auto'], //宽高
                        btn:['确定','取消'],
                        content: '<div style="height: 195px;padding: 15px !important;">'+
                        '<form class="layui-form" action="">'+
                        '<div class="layui-form-item layui-form-text" >'+
                        ' <input type="number"  placeholder="请输入费用" class="layui-input" id="money" name="money" />'+
                        '</div>'+
                        '<div class="layui-form-item layui-form-text" >'+
                        ' <textarea id="description" placeholder="请输入备注" style="width:369px;height: 135px;!important;"></textarea>'+
                        '</div>'+
                        '</form>'+
                        '</div>'
                        ,success:function(){

                        }
                        ,yes:function (){
                            var money = $("#money").val();
                            if(money == null || money == ""){
                                dialogUtil.alert("请填写费用");
                                return false;
                            }
                            var description = $("#description").val();
                            if(description == null || description == ""){
                                dialogUtil.alert("请填写备注");
                                return false;
                            }
                            var params={
                                "id":id,
                                "money":money,
                                "description":description
                            }
                            $.post("/webMember/updateScore", params, function (result) {
                                layer.close(index);
                                if (result.code === 0) {
                                    //操作成功
                                    tableIns.reload();
                                } else {
                                    //操作失败
                                    dialogUtil.alert(result.msg);
                                }
                            }, "json");
                        }
                        ,btn2: function(index, layero){

                        }
                    });
                } else if (layEvent === 'del') {
                    pageUtil.delete("确定删除该项吗？", "/webMember/delete", {
                            "id": data.id,
                            "_method": "DELETE"
                        },
                        function(data) {
                            tableIns.reload();
                        });
                }
            });
    })</script>
</body>

</html>